package com.gujia.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class ConnectionUtils {


    public static Connection getConnction() throws IOException, TimeoutException {

        // 定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("127.0.0.1");
        //端口
        factory.setPort(5672);//amqp协议 端口 类似于mysql的3306
        //设置账号信息，用户名，密码，vhost
        factory.setVirtualHost("/vhost_gujia");
        factory.setUsername("gujia");
        factory.setPassword("gujia");

        //通过工程获取连接
        Connection connection = factory.newConnection();

        return connection;

    }
}
